package sort;

import java.util.Arrays;

/**
 * ClassName: QuickSort
 * Package: sort
 * Description:
 *
 * @Author fjorid
 * @Create 2025/2/18 18:17
 * @Version 1.0
 */
public class QuickSort {
    public static void main(String[] args) {
        int[] arry = {11,5,4,9,8,2,3,7,6,-5,-9,0};
        quickSort(arry,0,arry.length-1);
        System.out.println(Arrays.toString(arry));

    }
    public static void quickSort(int arry[],int left ,int right){
        if(left >= right){
            return;
        }
        int l = left;
        int r = right;
        while(l < r){
            while (l < r && arry[r] <= arry[left] ){//这部分的思想也是数组反转的一个写法的思想
                r--;
            }
            while(l < r && arry[l] >= arry[left]){//改变排序顺序只要改这两个while里的不等号号就行
                l++;
            }
            if(r == l){
                int temp = arry[l];
                arry[l] = arry[left];
                arry[left] = temp;
            }else{
                int temp = arry[l];
                arry[l] = arry[r];
                arry[r] = temp;
            }
        }
        quickSort(arry,left,r-1);
        quickSort(arry,r+1,right);
    }
}
